# 长度最小的子数组
def smallest_subarray(nums: list[int], s: int) -> int:
    left, right, length, sum, min_value = 0, 0, len(nums), 0, float('inf')
    while (right < length):
        # 滑动窗口的数据总和
        sum += nums[right]
        while (sum >= s):
            # 数据总和大于期待值后 拿到最短路径 并窗口开始右滑
            min_value = min(min_value, right - left + 1)
            # 弹出滑动窗口的最左端数据, 替换为左端数据+1
            sum -= nums[left]
            left += 1
        right += 1
    return min_value
print(smallest_subarray([2, 3, 1, 2, 4, 3], 7))
